package com.base.thread.battle;

/**
 * 舞台线程
 *
 * @author innocent
 * @date 2019/1/24 11:52
 */
public class Stage extends Thread {
    @Override
    public void run() {
        //隋朝军队线程
        ArmyRunnable armyTaskOfSuiDynasty = new ArmyRunnable();
        //农民军线程
        ArmyRunnable armyTaskOfRevolt  = new ArmyRunnable();

        Thread armyOfSuiDynasty = new Thread(armyTaskOfSuiDynasty,"隋朝军队");
        Thread armyOfRevolt = new Thread(armyTaskOfRevolt,"农民军");

        //开始作战
        armyOfSuiDynasty.start();
        armyOfRevolt.start();

        //舞台线程睡眠
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //双方停止作战
        armyTaskOfSuiDynasty.keepRunning = false;
        armyTaskOfRevolt.keepRunning = false;


    }

    public static void main(String[] args) {
        System.out.println("-----开始表演-----");
        new Stage().start();
        System.out.println("-----表演结束-----");
    }
}
